<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            全国送
            <small>抽佣</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">全国送抽佣账单</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="tab-content">
            <div class="tab-pane active" id="tab_0">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="{:U('index')}" method="get" pjax-container="">
                                <fieldset>
                                    <div class="btn-group">时间段</div>
                                    <div class="input-group date form_datetime">
                                        <input id="start_time" class="form-control" type="text" name="start_time" value="{$_GET['start_time']|default='开始时间'}" readonly>
                                    </div>
                                    <div class="btn-group">-</div>
                                    <div class="input-group date">
                                        <input id="end_time" class="form-control" type="text" name="end_time" value="{$_GET['end_time']|default='结束时间'}" readonly>
                                    </div>
                                    <select class="form-control" name="local_id" style="height: 30px; font-size: 12px;">
                                        <option value="" <if condition="local_id eq ''">selected="selected"</if>>门店名称</option>
                                        <if condition="$locals neq ''">
                                            <volist name="locals" id="vo">
                                                <option value="{$vo.local_id}" <if condition="$_GET['local_id'] eq $vo['local_id']">selected="selected"</if>>{$vo.local_name}</option>
                                            </volist>
                                        </if>
                                    </select>
                                    <select class="form-control" name="state" style="height: 30px; font-size: 12px;">
                                        <option value="" <if condition="$_GET['state'] eq ''">selected="selected"</if>>结算状态</option>
                                        <option value="0" <if condition="$_GET['state'] eq '0'">selected="selected"</if>>结算中</option>
                                        <option value="1" <if condition="$_GET['state'] eq '1'">selected="selected"</if>>完成</option>
                                        <option value="2" <if condition="$_GET['state'] eq '2'">selected="selected"</if>>有异议</option>
                                    </select>
                                    <div class="input-group input-group-sm">
                                        <div class="input-group input-group-sm">
                                            <input type="hidden" name="search_field" value="{$search_field|default='account_id'}">
                                            <input type="text" class="form-control" placeholder="结算单号" name="search" value="{$search}">
                                        </div>
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>

                        <div class="btn-group pull-left" style="margin-right: 10px">
                            <a href="{:U('add')}" class="btn btn-sm btn-success"><i
                                    class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
                        </div>

                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <!--<th><input type="checkbox" class="grid-select-all"></th>-->
                                <th>ID<a class="fa fa-fw fa-sort" href="{:U('index',array('p'=>$p,'order_field'=>'id','order'=>$order), '')}"></a></th>
                                <th>店铺名</th>
                                <th>结算单号</th>
                                <th>结算日期</th>
                                <th>结算佣金金额</th>
                                <th>经办人</th>
                                <th>是否开票</th>
                                <th>备注说明</th>
                                <th>结算状态</th>
                                <th>操作</th>
                            </tr>
                            <volist name="list" id="vo">
                            <tr>
                                <!--<td><input type="checkbox" class="grid-item" data-id="{$vo.id}"></td>-->
                                <td>{$vo.id}</td>
                                <td>{$vo.local_name}</td>
                                <td>{$vo.account_id}</td>
                                <td>{$vo.create_time|date='Y-m-d', ###}</td>
                                <td><code><php>
                                    if($vo['qgs_reality_money'] != 0.00){
                                        echo $vo['qgs_reality_money'];
                                    }else{
                                        echo $vo['order_yongjin'] - $vo['order_other'] - $vo['order_bank'];
                                    }
                                </php></code></td>
                                <td>{$vo.handle_name}</td>
                                <td>{$vo['is_ticket'] == 1 ? '是': '否'}</td>
                                <td>{$vo.remark}</td>
                                <td>
                                    <if condition="$vo['state'] eq 0">
                                        结算中
                                    <elseif condition="$vo['state'] eq 1"/>
                                        完成
                                    <elseif condition="$vo['state'] eq 2"/>
                                        <code>有异议</code>
                                    </if>
                                </td>
                                <td>
                                    <if condition="$vo['state'] eq 0">
                                        <a href="{:U('edit', array('id'=>$vo['id']), '')}" class="btn btn-sm btn-primary grid-refreshe">编辑</a>

                                        <elseif condition="$vo['state'] eq 1"/>
                                        <a href="{:U('view', array('id'=>$vo['id']), '')}" class="btn btn-sm btn-success grid-refreshe">查看</a>
                                        <if condition="$vo['money_img'] eq ''">
                                            <a class="btn btn-sm btn-info grid-refreshe addimg" data-id="{$vo.id}">添加打款信息</a>
                                        </if>
                                        <elseif condition="$vo['state'] eq 2"/>
                                        <a href="{:U('edit', array('id'=>$vo['id']), '')}" class="btn btn-sm btn-primary grid-refreshe">编辑</a>
                                        <a href="javascript:void(0);" data-id="{$vo.id}" class="btn btn-sm btn-danger _delete">解决异议</a>
                                    </if>
                                    <if condition="$vo['state'] neq 1">
                                        <a href="{:U('delete', array('id'=>$vo['id']), '')}" class="btn btn-sm btn-success grid-refreshe">删除</a>
                                    </if>
                                </td>
                            </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                        {$page}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>

        </div>
    </section>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    上传打款信息图片
                </h4>
            </div>
            <div class="modal-body">
                <form action="" role="form" id="purchase-mark">
                    <div class="form-group">
                        <label for="exampleInputEmailbz">上传图片</label>
                        <input class="form-control" type="file" id="image" data-max-file-count="1" hidden/>
                        <input type="hidden" id="image_action"/>
                        <input type="hidden" name="id" value="">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" class="btn btn-primary  mark-submit">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 底部 -->
<include file="Public/common_footer"/>
<script src="/Public/admin/laydate/laydate.js"></script>
<link rel="stylesheet" href="/Public/admin/fileinput/fileinput.min.css">
<script src="/Public/admin/fileinput/fileinput.min.js"></script>
<script data-exec-on-popstate>
	function layerTime(){
        var start = {
            elem: "#start_time",
            format: 'YYYY-MM-DD',
            min: '1970-01-01 00:00:00', //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: false,
            istoday: false,
            choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: "#end_time",
            format: 'YYYY-MM-DD',
            min: '1970-01-01 00:00:00',
            max: '2099-06-16 23:59:59',
            istime: false,
            istoday: false,
            choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    }
    $(function () {
		layerTime();
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('._delete').click(function () {
            if(!confirm("确认问题已处理")){
                return false;
            }
            var id = $(this).attr('data-id');
            if (id) {

                $.ajax({
                    type: "POST",
                    url: "{:U('doneyiyi')}",
                    data: {id:id},
                    success: function(msg){
                        alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });
        $('.addimg').on('click', function () {
            var id = $(this).data('id');
            $('#myModal').find('input[name=id]').val(id);
            $('#myModal').modal('show');
        });

        $('.mark-submit').on('click', function () {
            var id = $(this).parents('#myModal').find('input[name=id]').val();
            var img = $(this).parents('#myModal').find('input[name=img]').val();
            $.ajax({
                type: "POST",
                url: "{:U('uploadimg')}",
                data: {id:id,img:img},
                success: function(msg){
                    alert(msg.message);
                    $('#myModal').modal('hide');
                    window.location.reload();
                },
                error: function (msg) {
                    alert(msg.message);
                }
            });
        });

        $("#image").fileinput({
                    overwriteInitial: true,
                    dropZoneEnabled: false,
                    uploadUrl: '/admin/upload/index/"',
                    language: 'zh',
                    showRemove: false,
                    maxFileCount: 1,
                    browseClass: 'btn btn-primary btn-docup',
                    showPreview: true,
                    uploadClass: 'btn btn-default btn-docup',
                    allowedFileTypes: ["image"],
                    browseLabel: "添加图片",
                    uploadLabel: "上传图片",
                    initialCaption:"{$carousel['img']}",
                <if condition = "(!empty($carousel['img']))">
                initialPreview:['<img src="/Uploads/{$carousel[img]}" class="file-preview-image">']
        </if>
    }).on("fileuploaded", function (event, data, previewId, index) {
            var response = data.response;
            if (data.jqXHR.status == 200) {
                // ajax 成功返回数据写入
                $('.file-preview-frame').eq(index).append("<input class='abc' type='hidden' name='img' value='"+response+"'>");
            }
        });
        $("#image").on('filecleared', function(event) {
            $("#image_action").val(1);
        });
    });
</script>